package com.zhengxiang.onlinexamination.service.impl;

import com.alibaba.druid.sql.ast.SQLAdhocTableSource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhengxiang.onlinexamination.dao.SysPostMapper;
import com.zhengxiang.onlinexamination.dao.SysRoleMapper;
import com.zhengxiang.onlinexamination.entity.SysPost;
import com.zhengxiang.onlinexamination.entity.vo.SysPostVo;
import com.zhengxiang.onlinexamination.service.SysPostService;
import com.zhengxiang.onlinexamination.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {

    @Resource
    private SysPostMapper sysPostMapper;

    @Override
    public void addPost(SysPostVo sysPostVo) {
        sysPostMapper.insert(sysPostVo);
    }

    @Override
    public void delPost(SysPostVo sysPostVo) {
        sysPostMapper.deleteById(sysPostVo.getPostId());
    }

    @Override
    public IPage<SysPost> queryPostList(SysPostVo sysPostVo, Page page) {
        QueryWrapper<SysPost> q = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(sysPostVo.getPostName())){
            q.lambda().like(SysPost::getPostName,sysPostVo.getPostName());
        }
        if(StringUtils.isNotEmpty(sysPostVo.getPostCode())){
            q.lambda().like(SysPost::getPostCode,sysPostVo.getPostCode());
        }
        q.lambda().orderByAsc(SysPost::getPostSort);
        return sysPostMapper.selectPage(page,q);
    }

    @Override
    public SysPost queryPostInfo(SysPostVo sysPostVo) {
        return sysPostMapper.selectById(sysPostVo);
    }

    @Override
    public void updatePost(SysPostVo sysPostVo) {
        sysPostMapper.updateById(sysPostVo);
    }
}
